package br.urca.impl;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;

import br.urca.dao.BiAutoresDAO;
import br.urca.model.BiAutores;

@Transactional
public class JPABiAutoresDAO implements BiAutoresDAO {
	
	private EntityManager manager;
	
	public JPABiAutoresDAO() {
		this(null);
	}
	
	@Inject
	public JPABiAutoresDAO(EntityManager manager) {
		this.manager = manager;
	}

	@Override
	public BiAutores getAutorPorId(Integer codAutor) {
		return this.manager
				.createQuery(
						"SELECT b FROM BiAutores b WHERE b.codAutor = :codigo",
						BiAutores.class).setParameter("codigo", codAutor)
				.getSingleResult();
	}

}
